/* 
 *   Date       Developer   Description
 *   
 *
 *   Classname:  zzz.test.component.direct.Test01
 * 
 *   Date:   2014-3-7
 * 
 *   The source code contained in this listing is proprietary to
 *   HLJ POST YITONG INFO-NET CO.,LTD.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2014 HLJ POST YITONG INFO-NET CO.,LTD.
 */
package com.titan.demo.camel.sample.component.direct;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;

import com.titan.core.utils.debug.Timer;
import com.titan.demo.camel.utils.RunCamel;


/**
 * 使用direct控制路由
 *
 */
public class Test01 {

    public static void main(String[] args) {
        Timer timer = Timer.$();
        try {
        	new RunCamel() {
				protected void execute(CamelContext context, ProducerTemplate producer, ConsumerTemplate consumer) throws Exception {
		            for (int i = 0; i < 100; i++) {
//		                System.out.println("begin run ["+i+"] ......");
		                long time = System.currentTimeMillis();
		                producer.sendBody("direct:a", null);
	                    time = System.currentTimeMillis() - time;
	                    System.out.println("["+i+"]["+time+"] 期望的返回结果。");
		            }
				}
        	}.run(new RouteBuilder() {
                public void configure() {
                    from("direct:a?block=true").to("direct:b");
                    from("direct:b").to("direct:c");
                    from("direct:c").process(new Processor() {
                        public void process(Exchange e) {
                        }
                    });
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            timer.print("执行总用时");
        }
    }

}

